﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using TileDemo.Resources;

namespace TileDemo
{
    public partial class MainPage : PhoneApplicationPage
    {
        public MainPage()
        {
            InitializeComponent();
            ApplicationTile();
        }

        private void ApplicationTile() 
        {
            //Create application tile, Flip tile
            TileHelper _TileHelper = new TileHelper();
            _TileHelper.tileUri = new Uri("/MainPage.xaml", UriKind.Relative);
            _TileHelper.tileData = new FlipTileData()
            {
                Title = "Customize Fisrt Tile",
                BackTitle = "WP8 Flip Tile",
                BackContent ="Flip Live Tile",
                WideBackContent = "WP8 Flip Tile Wide",
                Count = 10, // value between 1 and 99. Value 0 count not be displayed
                SmallBackgroundImage = new Uri("/Assets/Flip/159x159.png", UriKind.Relative),
                BackgroundImage = new Uri("/Assets/Flip/336x336.png", UriKind.Relative),
                WideBackgroundImage = new Uri("/Assets/Flip/691x336.png", UriKind.Relative)
            };

            _TileHelper.Update();
        }

        private void FlipTile_Click(object sender, RoutedEventArgs e)
        {
            //Create second tile Flip tile
            TileHelper _TileHelper = new TileHelper();
            _TileHelper.tileUri = new Uri("/MainPage.xaml?id=flip", UriKind.Relative);
            _TileHelper.tileData = new FlipTileData()
            {
                Title = "Customize Second Flip Tile",
                BackTitle = "WP8 Second Flip Tile",
                BackContent = "Second Flip Live Tile",
                WideBackContent = "WP8 Second Flip Tile Wide",
                Count = 99,// value between 1 and 99. Value 0 count not be displayed
                SmallBackgroundImage = new Uri("/Assets/Flip/A159.png", UriKind.Relative),
                BackgroundImage = new Uri("/Assets/Flip/A336.png", UriKind.Relative),
                WideBackgroundImage = new Uri("/Assets/Flip/A691.png", UriKind.Relative)
            };

            _TileHelper.FindDelete("flip");
            _TileHelper.Create();
        }

        private void IconicTile_Click(object sender, RoutedEventArgs e)
        {
            //Create second tile Iconic tile
            TileHelper _TileHelper = new TileHelper();
            _TileHelper.tileUri = new Uri("/MainPage.xaml?id=iconic", UriKind.Relative);
            _TileHelper.tileData = new IconicTileData()
            {
                Title = "Customize Second Iconic Tile",
                Count = 45,// value between 1 and 99. Value 0 count not be displayed
                WideContent1 = "Wide 1 WP8 Second Iconic Tile",
                WideContent2 = "Wide 2 WP8 Second Iconic Tile",
                WideContent3 = "Wide 3 WP8 Second Iconic Tile",
                SmallIconImage = new Uri("/Assets/Iconic/110x110.png", UriKind.Relative),
                IconImage = new Uri("/Assets/Iconic/202x202.png", UriKind.Relative)
               /* BackgroundColor = */ // alter tile color, assign default theme color case none  
            };

            _TileHelper.FindDelete("iconic");
            _TileHelper.Create();
        }
        /* Cycle tile dont suporte over 9 picture */ 
        private void CycleTile_Click(object sender, RoutedEventArgs e)
        {
            //Create second tile Cycle tile
            TileHelper _TileHelper = new TileHelper();
            _TileHelper.tileUri = new Uri("/MainPage.xaml?id=cycle", UriKind.Relative);
            _TileHelper.tileData = new CycleTileData()
            {
                Title = "Customize Second Flip Tile",
                Count = 71,// value between 1 and 99. Value 0 count not be displayed
                SmallBackgroundImage = new Uri("/Assets/Cycle/159x159.png", UriKind.Relative),
                CycleImages = new Uri[]
                {
                  new Uri("Assets/Cycle/001.jpg", UriKind.Relative), 
                  new Uri("Assets/Cycle/002.jpg", UriKind.Relative), 
                  new Uri("Assets/Cycle/003.jpg", UriKind.Relative), 
                  new Uri("Assets/Cycle/004.jpg", UriKind.Relative), 
                  new Uri("Assets/Cycle/005.jpg", UriKind.Relative), 
                  new Uri("Assets/Cycle/006.jpg", UriKind.Relative), 
                  new Uri("Assets/Cycle/007.jpg", UriKind.Relative), 
                  new Uri("Assets/Cycle/008.jpg", UriKind.Relative), 
                  new Uri("Assets/Cycle/009.jpg", UriKind.Relative),                 
                }
            };

            _TileHelper.FindDelete("cycle");
            _TileHelper.Create();
        }
    }
}